package com.lgc.demo.lambdaTest.testCompare;


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args){
        List<User> userList=new ArrayList<>();
        userList.add(new User("join",18));
        userList.add(new User("smith",28));

        List<User> newUserList = userList.stream().filter(p->p.getAge()==18).collect(Collectors.toList());

        write(userList);

        userList.sort(Comparator.comparing(User::getAge).reversed());

        write(userList);

        Collections.sort(userList,Comparator.comparingInt(p->p.getAge()));

        write(userList);

        List<String> aa = userList.stream().map(User::getName).collect(Collectors.toList());

        aa.forEach(p->System.out.println(p));

//        userList.forEach(p->{
//            System.out.println(this.toString());
//            System.out.println(p.getName());
//        });
//
//        userList.forEach(new Consumer<Integer>() {
//            @Override
//            public void accept(Integer integer) {
//                System.out.println(this.toString());
//            }
//        });
    }

    private static void write(List<User> userList){
        System.out.println("-------");
        userList.forEach(p->System.out.println(p.getName()+"--"+p.getAge().toString()));
    }

//    public void doSth() {
//        List<Integer> integers = Arrays.asList(2, 4, 6, 8);
//        integers.forEach(x -> {
//            System.out.println(this.toString());
//            System.out.println(x);
//        });
//
//    }

}

class User {
    private String name;

    public String getName() {
        return name;
    }

    public Integer getAge() {
        return age;
    }

    private Integer age;

    public User(String name, Integer age) {
        this.name = name;
        this.age = age;
    }
}
